﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap.Configuration.DSL;
using Core.IRepository;
using System.Configuration;
using Repositories;
using StructureMap;
using StructureMap.Pipeline;
using Core.Domain;
using StructureMap.Graph;
using Core.Dtos;
using Insurance.Repositories;
using Core.IRepository.Office;

namespace DI
{
    public class RepositoryRegistry : Registry
    {             
        public RepositoryRegistry(ILifecycle lifecycle)
        {
            //dbcontext
            For<OfficeDbContext>().LifecycleIs(lifecycle);                                    
            
            Scan(x =>
            {
                x.Assembly("Insurance.Repositories");
                x.Include(t => !t.IsAbstract && (t.Name.EndsWith("Repository") || t.Name.EndsWith("UnitOfWork")));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });
            Scan(x =>
            {
                x.Assembly("Share.Enterprise");
                x.Include(t => !t.IsAbstract && (t.Name.EndsWith("Repository") || t.Name.EndsWith("UnitOfWork")));
                x.WithDefaultConventions().OnAddedPluginTypes(c => c.LifecycleIs(lifecycle));
            });

            For(typeof(IQueryHelper<>)).LifecycleIs(lifecycle).Use(typeof(QueryHelper<>));                        
            For(typeof(IOfficeRepository<,>)).LifecycleIs(lifecycle).Use(typeof(OfficeRepository<,>));
        }
    }
}
